<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阻止默认行为</title>
</head>
<body>
    <form action="http://www.itcast.cn">
        <input type="submit" value="提交">
    </form>

    <a href="http://www.baidu.com">百度一下</a>

    <script>
        const form = document.querySelector('form')

        form.addEventListener('submit',function(e){
            // 阻止默认行为
            e.preventDefault()
        })

        const a = document.querySelector('a')
        a.addEventListener('click', function(e){
            e.preventDefault()
        })
    </script>
</body>
</html>